<?php
/**
 * 适配器模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/8/29
 * Time: 14:36
 * File: Adpater.php
 */

/**
 * Interface IPlayer
 */
interface IPlayer
{
    public function Attack();
    public function Defense();
}

class Forward implements IPlayer
{
    public function Attack()
    {
        echo "前锋进攻";
    }

    public function Defense()
    {
        echo "前锋防御";
    }
}

class Center implements IPlayer
{
    public function Attack()
    {
        echo "中锋进攻";
    }

    public function Defense()
    {
        echo "中锋防御";
    }
}

/**
 * 待适配的对象
 * Class Yaoming
 */
class Yaoming
{
    public function test1()
    {
        echo "test1";
    }

    public function test2()
    {
        echo "test2";
    }
}

/**
 * 适配器类
 * Class Adapter
 */
class Adapter implements IPlayer
{
    private $player;

    public function __construct()
    {
        $this->player = new Yaoming();
    }

    public function Attack()
    {
        $this->player->test1();
    }

    public function Defense()
    {
        $this->player->test2();
    }
}

